package com.example.dddsample.infrastructure.persistence.assembler;

        import com.baomidou.mybatisplus.core.metadata.IPage;
        import com.example.commom.model.PageRows;
        import com.example.dddsample.domain.entity.CustomerAggregate;
        import com.example.dddsample.infrastructure.persistence.assembler.mapper.CustomerPoMapper;
        import com.example.dddsample.infrastructure.persistence.po.CustomerPo;
        import org.springframework.stereotype.Component;

        import java.util.List;

/**
 * @author: bebm
 * @date: 2022/3/29 14:42
 * @description:
 */
@Component
public class CustomerPoAssembler {

    public CustomerAggregate assemblerFromCustomerPo(CustomerPo customerPo) {
        return CustomerPoMapper.INSTANCE.fromCustomerPo(customerPo);
    }

    /**
     *
     * @param customerPoIpage
     * @return PageRows
     */
    public PageRows assemblerFromCustomerPo(IPage<CustomerPo> customerPoIpage) {
        List<CustomerAggregate> customerAggregates = CustomerPoMapper.INSTANCE
                .fromCustomerPo(customerPoIpage.getRecords());
        PageRows<CustomerAggregate> customerAggregatePageRows =
                new PageRows(customerAggregates, customerPoIpage.getTotal(),
                        (int) customerPoIpage.getCurrent(), (int) customerPoIpage.getSize());
        return customerAggregatePageRows;
    }
}
